package com.tarena.lbs.marketing.web.controller;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.marketing.web.service.UserCouponsService;
import com.tarena.lbs.pojo.marketing.param.UserCouponsParam;
import com.tarena.lbs.pojo.marketing.query.UserCouponCodeQuery;
import com.tarena.lbs.pojo.marketing.query.UserCouponQuery;
import com.tarena.lbs.pojo.marketing.vo.UserCouponsVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.ExecutionException;

@RestController
@Slf4j
public class UserCouponsController {
    @Autowired
    private UserCouponsService userCouponsService;
    //点击领取优惠券
    @PostMapping("/marketing/user/receive/save")
    public Result<Void> getCoupon(@RequestBody UserCouponsParam param)
            throws BusinessException, ExecutionException, InterruptedException {
        Long startTime=System.currentTimeMillis();
        userCouponsService.getCoupon(param);
        Long endTime=System.currentTimeMillis();
        log.info("领取优惠券时间差:{}MS",endTime-startTime);
        return Result.success();
    }

    //小程序用户查看领取列表
    @PostMapping("/marketing/user/receive/list")
    public Result<PageResult<UserCouponsVO>> userCouponsPage(@RequestBody UserCouponQuery couponQuery)
        throws BusinessException{
        return new Result<>(userCouponsService.userCouponsPage(couponQuery));
    }

    @PostMapping("/marketing/user/receive/detail")
    public Result<UserCouponsVO> userCouponsDetail(@RequestBody UserCouponCodeQuery query)
        throws BusinessException{
        return new Result<>(userCouponsService.userCouponsDetail(query));

    }
}
